Skip to content

Improve support for conditional Square payments - #2594

Open
Crabcyborg wants to merge 14 commits into
masterfrom
improve_support_for_conditional_square
Open

Improve support for conditional Square payments#2594
Crabcyborg wants to merge 14 commits into
masterfrom
improve_support_for_conditional_square

Conversation

@Crabcyborg

@Crabcyborg Crabcyborg commented Nov 19, 2025

Copy link
Copy Markdown
Contributor

Related issue https://github.com/Strategy11/formidable-pro/issues/6100

This is mostly copied from where I added the same support for Stripe Link (https://github.com/Strategy11/formidable-stripe/pull/332).

  • When the Payment field is conditionally hidden (or the section it is in is conditionally hidden), the submit button should not be disabled when Stripe Link is incomplete.
  • When the payment field is made visible, the submit button will be disabled if Stripe link is incomplete.

Summary by CodeRabbit

Bug Fixes

  • Improved Square payment form behavior when the card field is conditionally hidden or shown.
  • Prevented payment submission from being blocked when the card field is unavailable due to form conditions.
  • Improved initialization when the card field becomes visible.
  • Updated submit-button availability automatically as payment fields, sections, or button conditions change.

@Crabcyborg Crabcyborg changed the title Improve support for conditional square Improve support for conditional Square payments Nov 19, 2025
@Crabcyborg Crabcyborg added this to the 6.27 milestone Dec 8, 2025
@Crabcyborg Crabcyborg modified the milestones: 6.27, 6.28 Jan 5, 2026
@Crabcyborg Crabcyborg modified the milestones: 6.28, 6.29 Feb 12, 2026
@Crabcyborg Crabcyborg modified the milestones: 6.29, 6.30 Mar 9, 2026
@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0ff1f005-f9ca-478e-8fbb-03cb3e673eeb

📥 Commits

Reviewing files that changed from the base of the PR and between 13351f6 and fc9be06.

📒 Files selected for processing (1)
  • square/js/frontend.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • square/js/frontend.js

📝 Walkthrough

Walkthrough

Square card initialization and submission handling now account for conditionally hidden fields and sections. The frontend adds visibility checks, conditional submit-state logic, and mutation observers that resize the card and retoggle submission as visibility changes.

Changes

Square conditional visibility

Layer / File(s) Summary
Visibility and submit-state detection
square/js/frontend.js
Helpers detect hidden payment fields, parse form identifiers, and identify conditionally disabled submit buttons.
Submission gating updates
square/js/frontend.js
Validity handling and squareInit() preserve submission when the Square card is hidden and respect conditional submit-button rules.
Visibility mutation handling
square/js/frontend.js
Observers track payment-field, section, and submit-button changes. The frontend waits for visible layout, recalculates Square sizing, and restores submission state.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Form
  participant SquareCard
  participant PaymentField
  participant MutationObserver
  participant SubmitButton

  Form->>SquareCard: initialize payment field
  SquareCard->>SubmitButton: set state from conditional visibility
  PaymentField->>MutationObserver: emit attribute mutation
  MutationObserver->>Form: re-evaluate field and section state
  Form->>SubmitButton: enable or disable submission
  Form->>SquareCard: recalculate size when visible
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: improved handling of conditional Square payment behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch improve_support_for_conditional_square

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@deepsource-io

deepsource-io Bot commented Apr 27, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in e3ee649...fc9be06 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Aug 7, 2026 1:34p.m. Review ↗
JavaScript Aug 7, 2026 1:34p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

Comment thread square/js/frontend.js Outdated
Comment thread square/js/frontend.js Outdated
* @returns {bool}
*/
function submitButtonIsConditionallyDisabled( formId ) {
return submitButtonIsConditionallyNotAvailable( formId ) && 'disable' === __FRMRULES[ 'submit_' + formId ].hideDisable;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected string concatenation


In ES2015 (ES6), we can use template literals instead of string concatenation.

Comment thread square/js/frontend.js Outdated
* @returns bool
*/
function submitButtonIsConditionallyNotAvailable( formId ) {
var hideFields = document.getElementById( 'frm_hide_fields_' + formId );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected var, use let or const instead


It is recommended to use let or const over var.
This will help prevent re-declaration of variables that are in the global scope when using var.

Comment thread square/js/frontend.js Outdated
* @returns bool
*/
function submitButtonIsConditionallyNotAvailable( formId ) {
var hideFields = document.getElementById( 'frm_hide_fields_' + formId );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected string concatenation


In ES2015 (ES6), we can use template literals instead of string concatenation.

Comment thread square/js/frontend.js Outdated
*/
function submitButtonIsConditionallyNotAvailable( formId ) {
var hideFields = document.getElementById( 'frm_hide_fields_' + formId );
return hideFields && -1 !== hideFields.value.indexOf( '["frm_form_' + formId + '_container .frm_final_submit"]' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected string concatenation


In ES2015 (ES6), we can use template literals instead of string concatenation.

Comment thread square/js/frontend.js Outdated
*/
function submitButtonIsConditionallyNotAvailable( formId ) {
const hideFields = document.getElementById( `frm_hide_fields_${ formId }` );
return hideFields && hideFields.value.includes( `["frm_form_${ formId }_container .frm_final_submit"]` );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer using an optional chain expression instead, as it's more concise and easier to read


The optional chaining operator can be used to perform null checks before accessing a property, or calling a function.

@Crabcyborg Crabcyborg modified the milestones: 6.32, 6.33 Jun 16, 2026
@Crabcyborg Crabcyborg modified the milestones: 6.33, 6.34 Jul 14, 2026
@Crabcyborg
Crabcyborg marked this pull request as ready for review July 20, 2026 18:33
Comment thread square/js/frontend.js Outdated
*/
function submitButtonIsConditionallyNotAvailable( formId ) {
const hideFields = document.getElementById( `frm_hide_fields_${ formId }` );
return hideFields && hideFields.value.includes( `["frm_form_${ formId }_container .frm_final_submit"]` );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer using an optional chain expression instead, as it's more concise and easier to read


The optional chaining operator can be used to perform null checks before accessing a property, or calling a function.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
square/js/frontend.js (1)

440-443: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Filter observed attributes for better performance.

Currently, the observer is triggered by all attribute changes (e.g., class, id) and then manually filtered in handleMutation. Supplying attributeFilter: [ 'style' ] prevents the browser from emitting unnecessary mutation events, providing a performance optimization.

⚡ Proposed optimization
 		observer.observe(
 			element,
-			{ attributes: true }
+			{ attributes: true, attributeFilter: [ 'style' ] }
 		);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@square/js/frontend.js` around lines 440 - 443, Update the MutationObserver
configuration in the observer.observe call to include attributeFilter containing
only “style”, while preserving attribute observation and the existing
handleMutation processing.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@square/js/frontend.js`:
- Line 414: Remove the redundant `'none' === mutation.target.display` condition
from the shouldEnable assignment in the mutation handling logic. Preserve the
existing squareCardElementIsComplete and squareIsConditionallyDisabled(form)
checks unchanged.
- Line 424: Update the mutation handling in listenForFieldMutations to guard the
cardGlobal.recalculateSize() call when cardGlobal is undefined during
initialization. Only recalculate the size once cardGlobal has been assigned,
while preserving the existing behavior after initializeCard completes.
- Around line 456-458: Update submitButtonIsConditionallyDisabled to use
optional chaining when accessing __FRMRULES[ `submit_${ formId }` ].hideDisable,
so missing global or form-specific rules safely yield an undefined property
result without throwing.

---

Nitpick comments:
In `@square/js/frontend.js`:
- Around line 440-443: Update the MutationObserver configuration in the
observer.observe call to include attributeFilter containing only “style”, while
preserving attribute observation and the existing handleMutation processing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 57968a5b-1493-4983-a3aa-53aa39a1c6d9

📥 Commits

Reviewing files that changed from the base of the PR and between 057c563 and eb724db.

📒 Files selected for processing (1)
  • square/js/frontend.js

Comment thread square/js/frontend.js Outdated
Comment thread square/js/frontend.js Outdated
Comment thread square/js/frontend.js
@Crabcyborg
Crabcyborg requested a review from garretlaxton July 20, 2026 19:09
@garretlaxton

Copy link
Copy Markdown

This fixes the submit issue, but when the payment field is hidden, it still throws an error Please enter a valid credit card when submitting the form.
image

@Crabcyborg

Copy link
Copy Markdown
Contributor Author

@garretlaxton Did you also mark the payment action as conditional? It looks like it's still triggering. The conditional logic needs to be on the field and the action.

@garretlaxton garretlaxton left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the issue. This looks good though. I was only able to find something unrelated to this PR https://github.com/Strategy11/formidable-pro/issues/6529

@Crabcyborg

Copy link
Copy Markdown
Contributor Author

Thanks @garretlaxton.

I did intend on properly supporting submit button conditional logic as well in this update.

I've made some new changes that should get it working as expected.

Can you test it against that new issue?

Thank you!

@Crabcyborg
Crabcyborg requested a review from garretlaxton August 7, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants